package leetcode.l0610;

import leetcode.l0606.Medium_删除链表的倒数第N个结点_19;

import java.lang.reflect.Array;
import java.util.*;

/**
 * @author Retain
 * @date 2021/6/10 8:34
 */
public class Easy_从尾到头打印链表_06 {
    public int[] reversePrint(ListNode head) {
        new ArrayList<>();

        ArrayDeque<Integer> deque = new ArrayDeque<>();
        while (head != null) {
            deque.push(head.val);
            head = head.next;
        }
        int[] arr = new int[deque.size()];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = deque.pop();
        }
        return arr;
    }

    static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
